<?php
include_once('common/header.php');
if($AppUI->id <= 0 || (isset($_SESSION['covers']) && ($_SESSION['covers'] <= 0))) {
	Vfriend_Function::redirect(HOST_BACKEND);
}
$arrParams 	= $objRequest->getParams();
$intAction 	= isset($arrParams['paction']) ? $arrParams['paction'] : 0;
$arrCoverId 	= isset($arrParams['pcoverid']) ? $arrParams['pcoverid'] : null;
$strBackUrl	= isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : HOST_BACKEND;
$intError  	= 0;
if($intAction && $arrCoverId) {
	$objCover	= new Cover();
	switch ($intAction) {
		case 1: // active		
			if(isset($_SESSION['covers']) && ($_SESSION['covers']&1<<5) != 0) {	
				foreach($arrCoverId as $row) {
					$intError  = $objCover->updateStatus($AppUI->id,$row,1,32);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 2: // delete
			if(isset($_SESSION['covers']) && ($_SESSION['covers']&1<<3) != 0) {				
				foreach($arrCoverId as $row) {
					$objCover->updateStatus($AppUI->id,$row,2,8);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 3:
			if(isset($_SESSION['covers']) && ($_SESSION['covers']&1<<4) != 0) {	
				foreach($arrCoverId as $row) {
					$intError  = $objCover->updateStatus($AppUI->id,$row,1,16);
				}
			}
			else {
				$intError = 1;
			}
			break;
		case 4: // delete database
			if(isset($_SESSION['covers']) && ($_SESSION['covers']&1<<3) != 0 && $AppUI->type > 1) {
				foreach($arrCoverId as $row) {
					$objCover->delete($AppUI->id,$row);
				}
			}
			else {
				$intError = 1;
			}
			break;	
	}
} else {
	$intError = 1;
}
if($intError == 0) {
	Vfriend_Function::setMsg($arrMessage[$intAction]);
} else {
	Vfriend_Function::setError($arrError[$intError]);	
}
Vfriend_Function::redirect($strBackUrl);
?>